| Total Complexity | 5 |
| Total Lines | 46 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import React, {Component} from 'react'; |
||
| 4 | |||
| 5 | class Report extends Component { |
||
| 6 | |||
| 7 | constructor() { |
||
| 8 | super(); |
||
| 9 | this.state = { |
||
| 10 | data: null, |
||
| 11 | number: null |
||
| 12 | }; |
||
| 13 | } |
||
| 14 | |||
| 15 | componentDidMount() { |
||
| 16 | // console.log(this.props); |
||
| 17 | fetch("https://me-api.listrom.me/reports/week/" + this.props.match.params.number) |
||
| 18 | .then(response => response.json()) |
||
| 19 | .then(data => { |
||
| 20 | this.setState({ data: data.data.text}); |
||
| 21 | // console.log(this.state.data); |
||
| 22 | }); |
||
| 23 | }; |
||
| 24 | |||
| 25 | componentDidUpdate(prevProps) { |
||
| 26 | if(prevProps.match.params.number !== this.props.match.params.number) { |
||
| 27 | fetch("https://me-api.listrom.me/reports/week/" + this.props.match.params.number) |
||
| 28 | .then(response => response.json()) |
||
| 29 | .then(data => { |
||
| 30 | this.setState({ data: data.data.text}); |
||
| 31 | // console.log(this.state.data); |
||
| 32 | }); |
||
| 33 | } |
||
| 34 | } |
||
| 35 | |||
| 36 | render() { |
||
| 37 | // console.log(this.props); |
||
| 38 | let editUrl; |
||
| 39 | |||
| 40 | if (auth.token !== "") { |
||
| 41 | editUrl = <Link className='button' to={`/reports/edit/${this.props.match.params.number}`}>Edit</Link>; |
||
| 42 | } |
||
| 43 | |||
| 44 | return ( |
||
| 45 | <main> |
||
| 46 | <h3>Kmom {this.props.match.params.number}</h3> |
||
| 47 | <p>{editUrl}</p> |
||
| 48 | <article dangerouslySetInnerHTML={{__html: this.state.data}}></article> |
||
| 49 | </main> |
||
| 50 | ); |
||
| 54 | export default Report; |